package com.zmx.doctor.adapter;

import android.app.Activity;
import android.os.Handler;
import android.os.Message;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.wang.adapters.adapter.BaseAdapterRvList;
import com.wang.adapters.base.BaseViewHolder;
import com.zmx.doctor.R;
import com.zmx.doctor.pojo.Prescription;

import butterknife.BindView;
import butterknife.ButterKnife;

public class PrescriptionMouldAdapter extends BaseAdapterRvList<PrescriptionMouldAdapter.ViewHolder, Prescription> {

    private Handler handler;
    private Integer logo;

    public PrescriptionMouldAdapter(Activity activity, Handler handler, Integer logo) {
        super(activity);
        this.handler = handler;
        this.logo = logo;
    }

    @Override
    protected void onBindVH(ViewHolder holder, int listPosition, Prescription prescription) {

        holder.title.setText(prescription.getTitle());
        holder.advice.setText(prescription.getAdvice());

        if (logo == 1) {
            holder.send.setVisibility(View.VISIBLE);
        } else {
            holder.send.setVisibility(View.GONE);
        }

        holder.send.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

                Message message = handler.obtainMessage();
                message.what = 2;
                message.obj = prescription.getId();
                handler.sendMessage(message);

            }
        });


    }

    @NonNull
    @Override
    protected ViewHolder onCreateVH(ViewGroup parent, LayoutInflater inflater) {

        PrescriptionMouldAdapter.ViewHolder holder = new PrescriptionMouldAdapter.ViewHolder(inflater.inflate(R.layout.adapter_prescription_mould, parent, false));
        return holder;
    }

    static class ViewHolder extends BaseViewHolder {

        @BindView(R.id.title)
        TextView title;
        @BindView(R.id.advice)
        TextView advice;
        @BindView(R.id.send)
        Button send;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }

    }


}
